<template>
  <div class="app-container">
    <wms-form v-model:query-params="queryParams" :form-list="formList" @query="getList" @export="handleExport">
    </wms-form>
    <wms-table class="table-click" :loading="loading" :data-list="outTaskList" :column="column" :pageInfo="queryParams"
      @get-list="getList" @row-click="handleRowClick" />
    <out-confirm v-if="showConfirm" v-model="showConfirm" :task-info="taskInfo" @refresh="getList" />
  </div>
</template>

<script setup name="OutTask">
import WmsTable from '@/components/WmsTable/index.vue'
import WmsForm from '@/components/WmsForm/index.vue'
import OutConfirm from '../outTask/outConfirm/index.vue'
import { listTask, getTask, cancelTask, addTask, updateTask } from "@/api/wms/task";
import { data, column, formList } from './index.js'
import { ref, reactive, getCurrentInstance, onMounted } from "vue";

const { proxy } = getCurrentInstance();
const queryParams = reactive(data.queryParams);

let showConfirm = ref(false)
let taskInfo = reactive({
  taskId: null,
})

const outTaskList = ref([]);
const loading = ref(true);

// ###相关方法###

/** 查询出库任务列表 */
function getList() {
  loading.value = true;
  listTask(proxy.addDateRange(queryParams, queryParams.dateRange)).then(response => {
    outTaskList.value = response.rows;
    queryParams.total = response.total;
    loading.value = false;
  });
}

function handleRowClick(row) {
  taskInfo.taskId = row.taskId
  showConfirm.value = true
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  queryParams.dateRange = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('wms/task/export', {
    ...queryParams
  }, `出库任务_${new Date().getTime()}.xlsx`)
}

getList();
</script>
